home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / buildCameraBookmarkMenu.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  9.9 KB  |  354 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  31 April 1997
  22. //  Author:         cdt
  23. //
  24. //  Description:
  25. //      This implements the user interface for camera bookmarks.
  26. //
  27.  
  28. proc buildBookmarkList(string $camera)
  29. {
  30.     int $selected[] = `textScrollList -q -selectIndexedItem list`;
  31.  
  32.     textScrollList -e -removeAll list;
  33.  
  34.     string $bookmarks[] = `listConnections ($camera+".bookmarks")`;
  35.  
  36.     for ( $item in $bookmarks)
  37.         textScrollList -e -append $item list;
  38.  
  39.     // Was something selected and are there remaining bookmarks ?
  40.     if (size($selected) > 0 && size($bookmarks) > 0) {
  41.         int $index = min($selected[0], size($bookmarks));
  42.         textScrollList -e -selectIndexedItem $index list;
  43.     }
  44. }
  45.  
  46. proc string selectedBookmark()
  47. {
  48.     string $items[] = `textScrollList -q -selectItem list`;
  49.     return (size($items) > 0) ? $items[0] : "";
  50. }
  51.  
  52. //
  53. //  Procedure Name:
  54. //      cameraBookmarkListCB
  55. //
  56. //  Description:
  57. //      This procedure is called when the user selects an item in the
  58. //      list. The name and description controls are updated to reflect
  59. //      this item.
  60. //
  61. global proc cameraBookmarkListCB(string $parent)
  62. {
  63.     setParent $parent;
  64.  
  65.     string $item = selectedBookmark();
  66.  
  67.     if ($item != "") {
  68.         textFieldGrp -e -text $item name;
  69.         textFieldGrp -e -text `getAttr ($item+".description")` desc;
  70.     }
  71.     else {
  72.         textFieldGrp -e -text "" name;
  73.         textFieldGrp -e -text "" desc;
  74.     }
  75. }
  76.  
  77. //
  78. //  Procedure Name:
  79. //      cameraBookmarkNameCB
  80. //
  81. //  Description:
  82. //      This procedure is called when the user has modified the
  83. //      text of the name control.
  84. //
  85. global proc cameraBookmarkNameCB(string $parent, string $camera)
  86. {
  87.     setParent $parent;
  88.  
  89.     string $item = selectedBookmark();
  90.  
  91.     // Nothing is selected ?
  92.     if ($item == "") {
  93.         // Create a new item and assign the name.
  94.  
  95.         $item = `cameraView -addBookmark -camera $camera`;
  96.         string $name = `textFieldGrp -q -text name`;
  97.         string $newName = `rename $item $name`;
  98.         buildBookmarkList($camera);
  99.         textScrollList -e -selectItem $newName list;
  100.         textFieldGrp -e -text $newName name;
  101.         textFieldGrp -e -text "" desc;
  102.     }
  103.     else {
  104.         // Modify name of the selected item.
  105.  
  106.         string $name = `textFieldGrp -q -text name`;
  107.         string $newName = `rename $item $name`;
  108.         buildBookmarkList($camera);
  109.         textFieldGrp -e -text $name name;
  110.     }
  111. }
  112.  
  113. //
  114. //  Procedure Name:
  115. //      cameraBookmarkNameCB
  116. //
  117. //  Description:
  118. //      This procedure is called when the user has modified the
  119. //      text of the description control.
  120. //
  121. global proc cameraBookmarkDescCB(string $parent, string $camera)
  122. {
  123.     setParent $parent;
  124.  
  125.     string $item = selectedBookmark();
  126.  
  127.     // Nothing is selected ?
  128.     if ($item == "") {
  129.         // Create a new item and assign the description.
  130.  
  131.         $item = `cameraView -addBookmark -camera $camera`;
  132.         string $description = `textFieldGrp -q -text desc`;
  133.         setAttr ($item+".description") -type "string" $description;
  134.         buildBookmarkList($camera);
  135.         textScrollList -e -selectItem $item list;
  136.         textFieldGrp -e -text $item name;
  137.     }
  138.     else {
  139.         // Modify description of the selected item.
  140.  
  141.         string $desc = `textFieldGrp -q -text desc`;
  142.         setAttr ($item+".description") -type "string" $desc;
  143.     }
  144. }
  145.  
  146. //
  147. //  Procedure Name:
  148. //      cameraBookmarkApplyCB
  149. //
  150. //  Description:
  151. //      This procedure is called when the user has pressed the apply
  152. //      button or double clicked on an item in the list. The selected
  153. //      view is applied to the camera.
  154. //
  155. global proc cameraBookmarkApplyCB(string $parent, string $camera)
  156. {
  157.     setParent $parent;
  158.  
  159.     string $item = selectedBookmark();
  160.  
  161.     if ($item != "") {
  162.         cameraView -e -camera $camera -setCamera $item;
  163.     }
  164. }
  165.  
  166. //
  167. //  Procedure Name:
  168. //      cameraBookmarkShelfCB
  169. //
  170. //  Description:
  171. //      This procedure is called when the user has pressed the shelf
  172. //      button.
  173. //
  174. global proc cameraBookmarkShelfCB(string $parent, string $camera)
  175. {
  176.     setParent $parent;
  177.  
  178.     string $item = selectedBookmark();
  179.  
  180.     if ($item != "") {
  181.         global string $gShelfTopLevel;
  182.  
  183.         if (`tabLayout -exists $gShelfTopLevel`) {
  184.             string $currentShelf = `tabLayout -q -selectTab $gShelfTopLevel`;
  185.  
  186.             string $cmdStr =
  187.                 "cameraView -e -camera "+$camera+" -setCamera "+$item;
  188.  
  189.             shelfButton
  190.                 -p ($gShelfTopLevel + "|" + $currentShelf)
  191.                 -image1 "commandButton.xpm"
  192.                 -label $item
  193.                 -style `shelfLayout -q -style $currentShelf`
  194.                 -width `shelfLayout -q -cellWidth $currentShelf`
  195.                 -height `shelfLayout -q -cellHeight $currentShelf`
  196.                 -c $cmdStr;
  197.         }
  198.     }
  199. }
  200.  
  201. //
  202. //  Procedure Name:
  203. //      cameraBookmarkNewCB
  204. //
  205. //  Description:
  206. //      This procedure is called when the user has pressed the new
  207. //      button. A new camera view using the current camera position is
  208. //      created.
  209. //
  210. global proc cameraBookmarkNewCB(string $parent, string $camera)
  211. {
  212.     setParent $parent;
  213.  
  214.     string $item = `cameraView -addBookmark -camera $camera`;
  215.     buildBookmarkList($camera);
  216.     textScrollList -e -selectItem $item list;
  217.     textFieldGrp -e -text $item name;
  218.     textFieldGrp -e -text "" desc;
  219. }
  220.  
  221. //
  222. //  Procedure Name:
  223. //      cameraBookmarkDelCB
  224. //
  225. //  Description:
  226. //      This procedure is called when the user has pressed the delete
  227. //      button or pressed the delete key. The selected view is deleted.
  228. //
  229. global proc cameraBookmarkDelCB(string $parent, string $camera)
  230. {
  231.     setParent $parent;
  232.  
  233.     string $item = selectedBookmark();
  234.  
  235.     if ($item != "") {
  236.         delete $item;
  237.         buildBookmarkList($camera);
  238.         cameraBookmarkListCB($parent);
  239.     }
  240. }
  241.  
  242. //
  243. //  Procedure Name:
  244. //      cameraBookmarkEditor
  245. //
  246. //  Description:
  247. //      Display an editor for editting the bookmarks associated with
  248. //      camera.
  249. //
  250. global proc cameraBookmarkEditor( string $camera )
  251. {
  252.     string $title = "Bookmark Editor (" + $camera + ")";
  253.  
  254.     string $win = `window -title $title -iconName "Bookmarks" cameraBookmarkWindow`;
  255.         formLayout winForm;
  256.             textScrollList -height 180 list;
  257.  
  258.             columnLayout -adj true col;
  259.                 textFieldGrp -l "Name" name;
  260.                 textFieldGrp -l "Description" desc;
  261.                 separator -style none -height 15;
  262.  
  263.                 formLayout btnForm;
  264.                     button -l "Apply" apply;
  265.                     button -l "Add To Shelf" shelf;
  266.                     button -l "New Bookmark" new;
  267.                     button -l "Delete" del;
  268.                 setParent ..;
  269.  
  270.                 button -l "Close" close;
  271.  
  272.  
  273.     formLayout -e
  274.         -af apply left 20
  275.         -af apply top 0
  276.         -ap apply right 5 25
  277.         -af apply bottom 10
  278.  
  279.         -af shelf top 0
  280.         -ap shelf left 5 25
  281.         -ap shelf right 5 50
  282.         -af shelf bottom 10
  283.  
  284.         -af new top 0
  285.         -ap new left 5 50
  286.         -ap new right 5 75
  287.         -af new bottom 10
  288.  
  289.         -af del right 20
  290.         -af del top 0
  291.         -ap del left 5 75
  292.         -af del bottom 10
  293.  
  294.         btnForm;
  295.  
  296.     formLayout -e
  297.         -af list left 15
  298.         -af list top 10
  299.         -af list right 15
  300.         -ac list bottom 10 col
  301.  
  302.         -af col left 10
  303.         -af col bottom 10
  304.         -af col right 10
  305.  
  306.         winForm;
  307.  
  308.    buildBookmarkList($camera);
  309.  
  310.    textScrollList -e -sc ("cameraBookmarkListCB "+$win) list;
  311.    textScrollList -e -dcc ("cameraBookmarkApplyCB "+$win+" "+$camera) list;
  312.    textScrollList -e -dkc ("cameraBookmarkDelCB "+$win+" "+$camera) list;
  313.    textFieldGrp -e -cc ("cameraBookmarkNameCB "+$win+" "+$camera) name;
  314.    textFieldGrp -e -cc ("cameraBookmarkDescCB "+$win+" "+$camera) desc;
  315.    button -e -c ("cameraBookmarkApplyCB "+$win+" "+$camera) apply;
  316.    button -e -c ("cameraBookmarkShelfCB "+$win+" "+$camera) shelf;
  317.    button -e -c ("cameraBookmarkNewCB "+$win+" "+$camera) new;
  318.    button -e -c ("cameraBookmarkDelCB "+$win+" "+$camera) del;
  319.    button -e -c ("deleteUI "+$win) close;
  320.  
  321.     showWindow $win;
  322. }
  323.  
  324. //
  325. //  Procedure Name:
  326. //      buildCameraBookmarkMenu
  327. //
  328. //  Description:
  329. //      Create a menu item for each the bookmark views associated with
  330. //      the current camera. New bookmarks can be created with or
  331. //      without a description.
  332. //
  333. global proc buildCameraBookmarkMenu( string $parent, string $panel )
  334. {
  335.     setParent -m $parent;
  336.  
  337.     menu -e -deleteAllItems $parent;
  338.  
  339.     string $camera = `modelPanel -q -camera $panel`;
  340.  
  341.     // Create a menu item for each bookmark
  342.  
  343.     string $bookmarks[] = `listConnections ($camera+".bookmarks")`;
  344.  
  345.     for ( $item in $bookmarks) {
  346.         menuItem -l $item
  347.             -c ("cameraView -e -camera "+$camera+" -setCamera "+$item);
  348.     }
  349.  
  350.     menuItem -divider true;
  351.  
  352.     menuItem -l "Edit Bookmarks..." -c ("cameraBookmarkEditor "+$camera);
  353. }
  354.